package mutilthread;

/**
 * Created with IntelliJ IDEA.
 * Description: 创建三个线程，分别打印A，B，C
 * User: Li_yizYa
 * Date: 2025—03—25
 * Time: 18:17
 */
public class Practice1 {
    private static Object Locker1 = new Object();
    private static Object Locker2 = new Object();
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            System.out.println("A");
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            synchronized (Locker1) {
                Locker1.notify();
            }
        });

        Thread t2 = new Thread(() -> {

            synchronized (Locker1) {
                try {
                    Locker1.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("B");
            synchronized (Locker2){
                Locker2.notify();
            }
        });

        Thread t3 = new Thread(() -> {
            synchronized (Locker2) {
                try {
                    Locker2.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("C");
        });

        t1.start();
        t2.start();
        t3.start();
    }
}
